<?php
require_once ('../../libraryfiles/config.php');

$action = isset ( $_GET ['action'] ) ? $_GET ['action'] : '';

switch ($action) {

	case 'add' :
		add ();
		break;

	case 'delselected' :
		deleteSelected ();
		break;

	case 'publish' :
		publishSelected ();
		break;
	case 'del' :
		deleteUserAccountType ();
		break;

	default :
		// if action is not defined or unknown
		// move to main user page
		header ( 'Location: index.php' );
		exit ();
}
function add() {
	$Name = trim ( $_POST ['txtName'] );
	if (empty ( $Name )) {
		header ( 'Location:' . base_url_admin . '/account_type/index.php?view=add&error=required' );
		exit ();
	}

	$desc = addslashes ( $_POST ['texteditor'] );

	$txtFee = $_POST ['txtFee'];
	$prolimited = $_POST ['prolimited'];

	$account_expire = $_POST ['account_expire'];
	if ($account_expire == '1') {
		$account_expire = $_POST ['txtexpired'];
	} else {
		$account_expire = '0';
	}
	$ID = $_POST ['hidid'];
	if (! empty ( $ID )) {
		$detectExist_q = '';
		$modify = true;
		$link = "&id=" . $ID;
		$detectExist_q .= " AND id != " . $ID;
	}
	if (isset ( $modify )) {
		$sql_u = "UPDATE tbluser_account_type SET account_type_name = '$Name', description = '$desc', account_price = '$txtFee', limit_product='$prolimited',account_expire='$account_expire', mdate=NOW() WHERE id = $ID";
		mysql_query ( $sql_u );
	} else {

		$sql = "INSERT INTO tbluser_account_type(account_type_name,description,account_price,limit_product,account_expire,status,cdate,mdate)
		       VALUES ('$Name', '$desc', '$txtFee', '$prolimited','$account_expire',1,NOW(),NOW())";

		mysql_query ( $sql );
	}
	header ( 'Location:' . base_url_admin . '/account_type/index.php?message=add' );
	exit ();
}
function deleteUserAccountType() {
	$id = ( int ) $_GET ['id'];
	$mysql = "DELETE FROM tbluser_account_type WHERE id = '" . $id . "'";
	mysql_query ( $mysql );
	header ( 'Location:' . base_url_admin . '/account_type/index.php?message=del' );
	exit ();
}
?>